﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace erpWebapiBack.ApplicationDev.mytest
{
    public class mytestService : MsSqlDbRepository
    {
        /// <summary>
        /// 主键查询
        /// </summary>
        /// <param name="keyValue"></param>
        /// <returns></returns>
        public mytestEntity GetMytestEntity(string keyValue)
        {
            return this.FindEntity<mytestEntity>(keyValue);
        }

        /// <summary>
        /// Func 委托查询
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public mytestEntity GetMytestEntity(string id, string name)
        {
            return this.FindEntity<mytestEntity>(o => o.mid == id && o.mname == name);
        }

        /// <summary>
        /// Sql 查询
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public IEnumerable<mytestEntity> GetMytestEntities(string query)
        {
            string execSql = "select * from mytest where mname like '%测试%'";

            return this.FindList<mytestEntity>(execSql);
        }


        /// <summary>
        /// 插入实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int InsertMytest(mytestEntity entity)
        {
            return this.Insert<mytestEntity>(entity);
        }

        /// <summary>
        /// 插入批量数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int InsertBranchMytest(IEnumerable<mytestEntity> entity)
        {
            return this.Insert<mytestEntity>(entity);
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int UpdateMytest(mytestEntity entity)
        {
            return this.Update<mytestEntity>(entity);
        }

        /// <summary>
        /// 删除一个
        /// </summary>
        /// <param name="mytestEntity"></param>
        /// <returns></returns>
        public int DeleteMytest(mytestEntity mytestEntity)
        {
            return this.Delete<mytestEntity>(mytestEntity);
        }

        /// <summary>
        /// 删除多个
        /// </summary>
        /// <param name="mytestEntities"></param>
        /// <returns></returns>
        public int DeleteBranchMytest(IEnumerable<mytestEntity> mytestEntities)
        {
            return this.Delete<mytestEntity>(mytestEntities);
        }

        /// <summary>
        /// SQL 语句执行
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public int ExecSqlUpdateData(string id,string name)
        {
            string execSql = "update mytest set mname='" + name + "' where mid='" + id + "'";

            return this.ExecuteBySql(execSql);
        }
    }
}
